package org.dromara.system.factory;

import cn.hutool.core.lang.Assert;

import org.dromara.system.enums.NotificationEnum;
import org.dromara.system.service.impl.trading.AbstractTradingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 王星
 * @date 2024/6/27 下午5:57
 */
@Component
public class PlatformTypeFactory {

    private static final Map<NotificationEnum, AbstractTradingService> FACTORY
            = new HashMap<>(16);

    @Autowired
    public PlatformTypeFactory(List<AbstractTradingService> services) {
        services.forEach(service -> {
            NotificationEnum typeEnum = service.getNotificationEnum();
            if (typeEnum != null) {
                Assert.isNull(FACTORY.putIfAbsent(typeEnum, service), "该查询策略类型已注册: {}",
                        typeEnum.getDesc());
            }
        });
    }

    public static AbstractTradingService get(NotificationEnum notificationEnum) {
        return FACTORY.get(notificationEnum);
    }
}
